<?php
abstract class printer {
    public $info = "this is printer";

    public function print_info() {
        print $this->info . '<br>';
    }

    abstract function print_custom_info();

}

class typeAInfo extends printer {

    public $info_str;

    function __construct($info) {
        $this->info_str = $info;
    }

    public function print_custom_info()
    {
        print "this is type A:" . $this->info_str;
    }

}

class typeBInfo extends printer{
    public $info_str;

    function __construct($info) {
        $this->info_str = $info;
    }

    public function print_custom_info()
    {
        print "this is type B:" . $this->info_str;
    }
}

class infoFactory {

    static function create($type, $info) {
        if ($type == 'A') {
            return self::getPrinterInfo(new typeAInfo($info));
        }
        else if ($type == 'B')
            return self::getPrinterInfo(new typeBInfo($info));
        else
            return false;
    }

    private static function getPrinterInfo(printer $printer) {
        $printer->print_info();
        return $printer;
    }

}


infoFactory::create('A', 'hello world A')->print_custom_info();
echo '<br>';
infoFactory::create('B', 'nihao B')->print_custom_info();